//
//  SmsCloudCityView.m
//  smsCloud
//
//  Created by 吴斌 on 2024/7/20.
//

#import "SmsCloudCityView.h"
@interface SmsCloudCityView()
@property (nonatomic, strong)UIImageView* smsCloudCityImgView;
@property (nonatomic, strong)UILabel * smsCloudCityLab;
@end
@implementation SmsCloudCityView
-(instancetype)init{
    if (self == [super init]) {
        [self smsCloudInitView];
    }
    return self;
}
- (void)smsCloudInitView{
    UIImageView* smsCloudHeadImgView = [[UIImageView alloc] init];
    smsCloudHeadImgView.userInteractionEnabled = YES;
    smsCloudHeadImgView.image = [SmsCloudHead SmsCloudImageNamed:@"smsCloudPhoneEar"];
    smsCloudHeadImgView.contentMode = UIViewContentModeScaleToFill;
    [self addSubview:smsCloudHeadImgView];
    [smsCloudHeadImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:32]));
        make.top.equalTo(@([SmsCloudHead SmsCloudScreewRatio:38]));
        make.width.equalTo(@([SmsCloudHead SmsCloudScreewRatio:34]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:34]));
    }];
    UILabel * smsCloudHeadLab = [[UILabel alloc] init];
    smsCloudHeadLab.font = [UIFont systemFontOfSize:[SmsCloudHead SmsCloudScreewRatio:32] weight:UIFontWeightRegular];
    smsCloudHeadLab.textColor = [SmsCloudHead SmsCloudColorHexString:@"#222222"];
    smsCloudHeadLab.text = @"选择国家地区";
    [self addSubview:smsCloudHeadLab];
    [smsCloudHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(smsCloudHeadImgView.mas_right).offset([SmsCloudHead SmsCloudScreewRatio:5]);
        make.centerY.equalTo(smsCloudHeadImgView);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:45]));
    }];
    UIView *smsCloudHeadView = [[UIView alloc] init];
    smsCloudHeadView.backgroundColor = [UIColor clearColor];
    smsCloudHeadView.layer.cornerRadius = [SmsCloudHead SmsCloudScreewRatio:10];
    smsCloudHeadView.layer.borderColor = [SmsCloudHead SmsCloudColorHexString:@"#A4A9BC"].CGColor;
    smsCloudHeadView.layer.borderWidth = [SmsCloudHead SmsCloudScreewRatio:2];
    smsCloudHeadView.clipsToBounds = YES;
    [self addSubview:smsCloudHeadView];
    [smsCloudHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:32]));
        make.right.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:32]));
        make.top.equalTo(smsCloudHeadLab.mas_bottom).offset([SmsCloudHead SmsCloudScreewRatio:22]);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:88]));
    }];
    self.smsCloudCityImgView = [[UIImageView alloc] init];
    self.smsCloudCityImgView.userInteractionEnabled = YES;
    self.smsCloudCityImgView.contentMode = UIViewContentModeScaleToFill;
    [smsCloudHeadView addSubview:self.smsCloudCityImgView];
    [self.smsCloudCityImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:31]));
        make.centerY.equalTo(smsCloudHeadView);
        make.width.equalTo(@([SmsCloudHead SmsCloudScreewRatio:34]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:34]));
    }];
    self.smsCloudCityLab = [[UILabel alloc] init];
    self.smsCloudCityLab.font = [UIFont systemFontOfSize:[SmsCloudHead SmsCloudScreewRatio:30] weight:UIFontWeightRegular];
    self.smsCloudCityLab.textColor = [SmsCloudHead SmsCloudColorHexString:@"#262729"];
    [smsCloudHeadView addSubview:self.smsCloudCityLab];
    [self.smsCloudCityLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.smsCloudCityImgView.mas_right).offset([SmsCloudHead SmsCloudScreewRatio:9]);
        make.centerY.equalTo(self.smsCloudCityImgView);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:42]));
    }];
    UIImageView* smsCloudGoImgView = [[UIImageView alloc] init];
    smsCloudGoImgView.userInteractionEnabled = YES;
    smsCloudGoImgView.image = [SmsCloudHead SmsCloudImageNamed:@"smsCloudPhoneGo"];
    smsCloudGoImgView.contentMode = UIViewContentModeScaleToFill;
    [smsCloudHeadView addSubview:smsCloudGoImgView];
    [smsCloudGoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:24]));
        make.centerY.equalTo(smsCloudHeadView);
        make.width.equalTo(@([SmsCloudHead SmsCloudScreewRatio:48]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:48]));
    }];
    UIButton * smsCloudGoBtn = [[UIButton alloc] init];
    [smsCloudGoBtn addTarget:self action:@selector(smsCloudGo) forControlEvents:UIControlEventTouchUpInside];
    [smsCloudHeadView addSubview:smsCloudGoBtn];
    [smsCloudGoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
    }];
}
-(void)setSmsCloudCityMdl:(SmsCloudCityModel *)smsCloudCityMdl{
    _smsCloudCityMdl = smsCloudCityMdl;
    if(_smsCloudCityMdl){
        self.smsCloudCityLab.text = _smsCloudCityMdl.info.name;
        [self.smsCloudCityImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://www.ydl.cool/img/static/guojia/guojia01/%@.png",_smsCloudCityMdl.info.code]] placeholderImage:[SmsCloudHead SmsCloudImageNamed:@"smsCloudLogo"]];
    }
}
- (void)smsCloudGo{
    if (self.SmsCloudSelectCityBlock) {
        self.SmsCloudSelectCityBlock();
    }
}
@end
